#ifndef FORM_JCMLXZ_H
#define FORM_JCMLXZ_H

#include <QWidget>
#include <QSqlQuery>
#include <QSqlError>
#include "threadyb.h"
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QNetworkInterface>
#include <QNetworkRequest>
#include <QJsonObject>
#include <QTimer>
#include <QByteArray>
#include <QPointer>

namespace Ui {
class Form_jcmlxz;
}

class Form_jcmlxz : public QWidget
{
    Q_OBJECT

public:
    explicit Form_jcmlxz(QWidget *parent = nullptr);
    ~Form_jcmlxz();

    bool download(QString);//执行下载操作
    bool putBaseIn( QJsonObject &in, QString code);
    bool saveFile(QString file_qury_no, QString jydm);

    bool validSave( QString);

    bool importData(QString);
    QString removeSpecialChar(QString s);

public slots:
    void onSqlFinished();

private slots:
    void closeEvent(QCloseEvent *event);
    void on_pbExit_clicked();
    void on_pbDownload_clicked();
    void on_pbImport_clicked();
    void on_pbQuery_clicked();
    void onTimeOut();
    void onTime0Out();
    void threadStatusChange(QString);

    //void postRequestFinished1(QNetworkReply *); //交易序列 1
    //void postRequestFinished2(QNetworkReply *); //交易序列 2


    void on_pbSimple_clicked();

private:

    Ui::Form_jcmlxz *ui;
    QSqlQuery *qro;
    QSqlQuery *qrm;
    QString sq;

    QTimer *tm;
    QTimer *tm0;

    QNetworkRequest request;
    QNetworkAccessManager manager;
    QNetworkReply * rpl ;

    //volatile bool businessFinish;    //医保交易完成标志
    bool businessSuccess;       //医保交易成功标志
    //QString jydm; //当前交易号
    QString currentMsgid;

    QString curStatus; //

    int pageSize;   //每页行数
    int pages;  //页数
    bool lastPage;  //是否最后一页

    bool hasZip;    //zip 库存在

    QString startDate;  //开始日期
    QString ver; //当前下载版本
    QString lastOperDate;   //最后一次下载日期,1312等交易使用
    QJsonObject retObj; //交易返回值

    int endrows;
    int nowrows;
};

class sqlThread : public QThread
{
    Q_OBJECT

public:
    sqlThread(QWidget * receiver);
    ~sqlThread();
signals:
    void statusChange(QString);
protected:
    void run();
private:
    QPointer<QWidget> m_receiver;
};

#endif // FORM_JCMLXZ_H
